function loadScript(url, callback) {
	var script = document.createElement("script");
	script.type = "text/javascript";
	if (script.readyState) {
		script.onreadystatechange = function() {
			if (script.readyState == "loaded" || script.readyState == "complete") {
				script.onreadystatechange = null;
				if(callback)callback();
				document.getElementsByTagName("head")[0].removeChild(this)
			}
		}
	} else {
		script.onload = function() {
			if(callback)callback();
			document.getElementsByTagName("head")[0].removeChild(this)
		}
	}
	script.src = url;
	document.getElementsByTagName("head")[0].appendChild(script)
}
function closeAndRefreshParent(){
	window.opener.location.reload();window.opener=null;window.close();
}

function getRequestUri(){
	var path = window.location.pathname;
	var idx = path.lastIndexOf(".");
	if (idx != -1) {
		path = path.substring(0, idx);
	}
	return path;
}

String.prototype.startWith=function(str){     
  var reg=new RegExp("^"+str);     
  return reg.test(this);        
}

String.prototype.endWith=function(str){     
  var reg=new RegExp(str+"$");     
  return reg.test(this);        
}


function formatSize(size, pointLength, units){
	var unit;
    units = units || [ 'B', 'K', 'M', 'G', 'TB' ];
    while ( (unit = units.shift()) && size > 1024 ) {
        size = size / 1024;
    }
    return (unit === 'B' ? size : size.toFixed( pointLength || 2 )) +
            unit;
}

$(document).ready(function(){
	//var userPic = $("#_user_picture").attr("src");
	//if(userPic==""){
	//	 $("#_user_picture").attr("src", $("#_user_picture").attr("onerror"));
	//}
	
	if($("#__admin_select_subject_id").length>0){
		var reqUri = getRequestUri();
		var subjectId = $("#__admin_select_subject_id").val();
		if(subjectId==-1 ){
			if($("#__conflictSuperAdmin").length>0 || reqUri==contextPath+"/media/post/admin_list/1"){
				location.href=contextPath+"/media/post/addSubjectList.do";
			}
		}
		if(subjectId!=-1 && reqUri==contextPath+"/media/post/addSubjectList"){
			location.href=contextPath+"/media/post/admin_list/1.do";
		}
	}
	/*if($(".top .department").length>0 && window.opener!=null){
		$(".top .department").hide();
	}*/
	
});